package com.lhb.mapper;


import com.github.pagehelper.Page;
import com.lhb.dto.UserAddDTO;
import com.lhb.dto.UserEditDTO;
import com.lhb.dto.UserPageQueryDTO;
import com.lhb.entity.User;
import com.lhb.vo.UserEditVO;
import com.lhb.vo.UserGetByIdVO;
import com.lhb.vo.UserPageQueryVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {


    /**
     * 查询是否有该用户
     * @param username
     * @return
     */
    @Select("select * from user where username=#{username}")
    User getByUsername(String username);

    /**
     * 分页查询
     *
     * @param userPageQueryDTO
     * @return
     */
    Page<UserPageQueryVO> pageQuery(UserPageQueryDTO userPageQueryDTO);

    /**
     * 根据id查询用户
     *
     * @param id
     * @return
     */
    @Select("select id,username, avatar_image, real_name, password, phone, id_card, sex from user where id=#{id}")
    UserGetByIdVO getById(Integer id);


    /**
     * 编辑用户
     * @param user
     * @return
     */
    void update(User user);


    /**
     * 修改用户状态
     * @param user
     */
    @Update("update user set status=#{status},update_user=#{updateUser},update_time=#{updateTime} where id=#{id}")
    void modifyStatus(User user);

    /**
     * 根据id删除用户
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    void deleteById(Integer id);

    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user(username, avatar_image, real_name, password, phone, id_card, sex,create_user,update_user,create_time,update_time) VALUES(#{username},#{avatarImage},#{realName},#{password},#{phone},#{idCard},#{sex},#{createUser},#{updateUser},#{createTime},#{updateTime})")
    void save(User user);
}
